import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

//FIXME Remove rations setting of "None"? Only happens when food == 0? 
//FIXME Remove pace setting of "Stopped"? Add "Rest" button to Turn screen?

/**
 * Represents the screen where pace and ration settings can be changed.
 */
public class PaceRationsPanel extends JPanel{

	private JComboBox paceBox;
	private JComboBox rationsBox;
	private JButton doneButton;
	private int paceIndex;
	private int rationsIndex;

	private Game game;
	
	
	/**
	 * Creates a panel where pace and rations settings can be changed.
	 * @param g - The current game
	 */
	public PaceRationsPanel(Game g) {

		game = g;
		
		setBorder(new EmptyBorder(5, 5, 5, 5));
		setLayout(null);
		
		paceBox = new JComboBox();
		paceBox.setModel(new DefaultComboBoxModel(new String[] {"Stopped", "Leisurely", "Steady", "Grueling"}));
		paceBox.setFont(new Font("Tahoma", Font.PLAIN, 12));
		paceBox.setBounds(331, 70, 139, 24);
		add(paceBox);
		
		rationsBox = new JComboBox();
		rationsBox.setModel(new DefaultComboBoxModel(new String[] {"None", "Bare-Bones", "Meager", "Normal", "Well-Fed"}));
		rationsBox.setFont(new Font("Tahoma", Font.PLAIN, 12));
		rationsBox.setBounds(331, 157, 139, 24);
		add(rationsBox);
		
		doneButton = new JButton("Done");
		doneButton.addActionListener(new ButtonListener());
		doneButton.setBounds(353, 264, 117, 25);
		add(doneButton);
		
		JLabel lblNewLabel = new JLabel("Pace:");
		lblNewLabel.setBounds(198, 75, 70, 19);
		add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Rations:");
		lblNewLabel_1.setBounds(198, 162, 70, 15);
		add(lblNewLabel_1);
	}
	
	
	/**
	 * Tells the panel what the currently selected pace and rations are.
	 * When the screen first appears, this insures that the combo boxes
	 * already show the current pace / rations, instead of just the first
	 * index.
	 * 
	 * @param paceIndex -- The current pace index (pace / PACE_MULTIPLIER)
	 * @param rationsIndex -- The current rations index
	 */
	public void updatePanel(int paceIndex, int rationsIndex){
		paceBox.setSelectedIndex(paceIndex);
		rationsBox.setSelectedIndex(rationsIndex);
	}
	
	/**
	 * Listener for the done button.
	 */
	private class ButtonListener implements ActionListener
	{

		@Override
		public void actionPerformed(ActionEvent e) 
		{
			//Done button was pressed
			paceIndex = (paceBox.getSelectedIndex());
			rationsIndex = rationsBox.getSelectedIndex();
			
			game.setPaceRations(paceIndex, rationsIndex);
			game.changePanel("TurnPanel");
		}
	}

}
